package com.patni.body.detail;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.patni.body.MainFrame;
import com.patni.detail1.bean.ModuleBean;

public class Module extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ModuleBean moduleBean;
	private JLabel imageLabel;
	private JLabel name;
	private JLabel autograph;
	public final static int moduleHeight=56;
public Module(ModuleBean moduleBean){
	this.moduleBean=moduleBean;
	initPanel();
	this.addMouseListener(new MouseListener() {
		
		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			setBg1();
		}
		
		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			setBg2();
		}
		
		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			setBg3();
			if(e.getClickCount()==2){
				OpenChat();
		}
		}});
}

public void OpenChat(){
	JFrame f=new JFrame("正在和"+moduleBean.getName()+"聊天");
	f.setBounds(300, 250, 400, 300);
	f.setVisible(true);
}

public Module(){}


public void setBg1(){

		this.setBackground(Color.white);
		MainFrame.j.repaint();
}

public void setBg2(){

	this.setBackground( Color.orange);
	MainFrame.j.repaint();
	
}

public void setBg3(){

	this.setBackground(Color.pink);
	MainFrame.j.repaint();
}

public void initPanel(){
	
	imageLabel=new ImageLabel(moduleBean.getImage());
	
	name=new JLabel(moduleBean.getName());
//	name.setForeground(Color.red);
	name.setForeground(Color.black);
	name.setFont(new Font("宋体",Font.PLAIN,12));
	autograph=new JLabel(moduleBean.getAutograph());
	autograph.setFont(new Font("宋体",Font.PLAIN,12));
	autograph.setForeground(Color.gray);
	name.setBounds(moduleHeight, 0, Detail1Pan.width, 20);
	autograph.setBounds(moduleHeight, 20, Detail1Pan.width, 15);
//	imageLabel.setBorder(BorderFactory.createEtchedBorder());
	this.setLayout(null);
	
	this.add(imageLabel);
	this.add(name);
	this.add(autograph);

	this.setSize(Detail1Pan.width,moduleHeight);
	this.setBackground(new Color(242,245,248));

}

}
